import { requestClient } from '#/api/request';

//
export async function getTradeGroup(data: any) {
  return requestClient.get('/tradeGroup', { params: data });
}

interface AccountParams {
  uid: string;
  key: string;
  secret: string;
  group: string;
  enabled: boolean;
}

export async function addAccountApi(data: AccountParams) {
  return requestClient.post('/address', data);
}

export async function editAccountApi(id: string, data: AccountParams) {
  return requestClient.put(`/address/${id}`, data);
}

export async function getAccountDetailApi(id: string) {
  return requestClient.get(`/address/${id}`);
}

export async function getAccountApi(pager: any) {
  return requestClient.get('/address', {
    params: pager,
  });
}

export async function deleteAccountDetailApi(id: string) {
  return requestClient.delete(`/address/${id}`);
}

export async function postAccountDetailApi(data: any) {
  return requestClient.post(`/trade`, data);
}

export function requestTradingObject(data: any) {
  return requestClient.get('/groups', { params: data });
}

/** 请求平台 */
export function reqPlatformList() {
  return requestClient.get('/platform');
}
/** 请求组 */
export function reqGroupList() {
  return requestClient.get('/accountGroup');
}
/** 编辑组 */
export async function editGroup(id: number, data: { name: string }) {
  return requestClient.put(`/accountGroup/${id}`, data);
}

/** 删除组 */
export async function deleteGroup(id: number) {
  return requestClient.delete(`/accountGroup/${id}`);
}
/** 新增组 */
export async function addGroup(data: { name: string }) {
  return requestClient.post('/accountGroup', data);
}

/** 请求账号列表 */
export function reqAccountList(data: any) {
  return requestClient.get('/account', { params: data });
}
/** 新增账号 */
export function addAccount(data: AccountParams) {
  return requestClient.post('/account', data);
}

/** 请求账号详情 */
export async function reqAccountDetail(id: number) {
  return requestClient.get(`/account/${id}`);
}

/** 编辑账号信息 */
export async function editAccount(id: number, data: AccountParams) {
  return requestClient.put(`/account/${id}`, data);
}

/** 删除账号 */
export async function deleteAccountByID(id: number) {
  return requestClient.delete(`/account/${id}`);
}

/** 下单 */
export async function reqTrade(data: any) {
  return requestClient.post(`/trade`, data);
}

interface IInitAccount {
  id: number | string;
  platform_id: number;
}
/**
 * @param data.id id 账号id
 * @param data.platform_id 平台id
 * @description 初始化账号
 * @returns {Promise}
 */
export function reqInitAccount(data: IInitAccount): Promise<any> {
  return requestClient.get(`/initAccount`, { params: data });
}

/** 下单 */
export async function reqInitAll(data: any) {
  return requestClient.post(`/batchAccount`, data);
}
